<?php
/**
 * Attraction represents an attraction and is child of an POI 
 */

class Attraction extends Model{
	
	public $id;
	public $location_id;
	public $name;
	public $description;
	public $radius;
	public $waittime;
	
	/**
	 * constructs parent
	 */
	function __construct() {
		parent::__contruct();
	}
	
	/** 
	 * Gets an Attraction object
	 * @param id The id of the attraction
	 * @return Attraction 
	 */	
	function get($id) {	
		$sth = $this->db->prepare('SELECT p.*, a.waittime, l.lat, l.lng FROM poi p
								   JOIN attraction a ON a.poi_id = p.id
								   LEFT JOIN location l ON l.id = p.location_id
								   WHERE p.id = :id');
		$sth->setFetchMode(PDO::FETCH_INTO, $this);	
		$sth->execute(array(':id' => $id));
		return $sth->fetch();			
	}
	
}

/**
 * AttractionList represents an attractionlist and is child of an POI 
 */
class AttractionList extends Model{
	
	/**
	 * constructs parent
	 */	
	function __construct() {
		parent::__contruct();
	}
	
	/** 
	 * Gets an Attraction objectlist
	 * @return AttractionList array
	 */	
	function get(){
		$sth = $this->db->prepare('SELECT p.*, a.*, l.lat, l.lng FROM poi p
								   JOIN attraction a ON a.poi_id = p.id
								   LEFT JOIN location l ON l.id = p.location_id');
		$sth->execute();
		return $sth->fetchAll(PDO::FETCH_ASSOC);
	}
}